#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>

int main()
{
    pid_t id = fork();
    if(id == 0)
    {
        //child
        int cnt = 5;
        while(cnt)
        {
            printf("I am child process, pid: %d, ppid: %d, cnt: %d\n",getpid(), getppid(), cnt);
            cnt--;
        
        }
        sleep(1);
        exit(100);
    }

    int status = 0;
    pid_t rid = waitpid(id, &status, 0);
    if(rid > 0)
    {
        printf("wait sucess. rid: %d, status: %d, exit signo: %d, exit code: %d\n",rid, status, status&0x7F, (status>>8)&0xFF);
    }
    return 0;
}

